﻿using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

// Token: 0x020003EC RID: 1004
public class ListDataLoader
{
	// Token: 0x06001906 RID: 6406 RVA: 0x000A2270 File Offset: 0x000A0470
	public ListDataLoader()
	{
		this.X_Num = -1;
		this.Y_Num = -1;
	}

	// Token: 0x06001907 RID: 6407 RVA: 0x000A22AC File Offset: 0x000A04AC
	public ListDataLoader(char separator, StringSplitOptions splitOptions)
	{
		this.X_Num = -1;
		this.Y_Num = -1;
		this.SetSeparator(separator, splitOptions);
	}

	// Token: 0x06001908 RID: 6408 RVA: 0x000A22F8 File Offset: 0x000A04F8
	public ListDataLoader(char[] separator, StringSplitOptions splitOptions)
	{
		this.X_Num = -1;
		this.Y_Num = -1;
		this.SetSeparator(separator, splitOptions);
	}

	// Token: 0x17000265 RID: 613
	// (get) Token: 0x06001909 RID: 6409 RVA: 0x000A2344 File Offset: 0x000A0544
	// (set) Token: 0x0600190A RID: 6410 RVA: 0x000A234C File Offset: 0x000A054C
	public int X_Num { get; private set; }

	// Token: 0x17000266 RID: 614
	// (get) Token: 0x0600190B RID: 6411 RVA: 0x000A2358 File Offset: 0x000A0558
	// (set) Token: 0x0600190C RID: 6412 RVA: 0x000A2360 File Offset: 0x000A0560
	public int Y_Num { get; private set; }

	// Token: 0x17000267 RID: 615
	public string this[int y, int x]
	{
		get
		{
			return this.Get(x, y);
		}
	}

	// Token: 0x0600190E RID: 6414 RVA: 0x000A2378 File Offset: 0x000A0578
	public void SetSeparator(char separator, StringSplitOptions splitOptions)
	{
		this.separator = new char[]
		{
			separator
		};
		this.splitOptions = splitOptions;
	}

	// Token: 0x0600190F RID: 6415 RVA: 0x000A2394 File Offset: 0x000A0594
	public void SetSeparator(char[] separator, StringSplitOptions splitOptions)
	{
		this.separator = separator;
		this.splitOptions = splitOptions;
	}

	// Token: 0x06001910 RID: 6416 RVA: 0x000A23A4 File Offset: 0x000A05A4
	public void SetList(List<List<string>> setList)
	{
		this.list = setList;
	}

	// Token: 0x06001911 RID: 6417 RVA: 0x000A23B0 File Offset: 0x000A05B0
	public bool Load_Text(TextAsset text, int x = -1, int y = -1)
	{
		StringReader stringReader = new StringReader(text.text);
		bool result = this.Load_Text(stringReader, x, y);
		stringReader.Close();
		return result;
	}

	// Token: 0x06001912 RID: 6418 RVA: 0x000A23DC File Offset: 0x000A05DC
	public bool Load_Text(string fullPath, int x = -1, int y = -1)
	{
		FileStream fileStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read);
		if (fileStream == null)
		{
			MonoBehaviour.print("读取失败: " + fullPath);
			return false;
		}
		StreamReader streamReader = new StreamReader(fileStream);
		bool result = this.Load_Text(streamReader, x, y);
		streamReader.Close();
		return result;
	}

	// Token: 0x06001913 RID: 6419 RVA: 0x000A2424 File Offset: 0x000A0624
	private bool Load_Text(TextReader reader, int x = -1, int y = -1)
	{
		this.X_Num = x;
		this.Y_Num = y;
		bool flag = this.X_Num == 0;
		int num = -1;
		string text;
		while ((text = reader.ReadLine()) != null)
		{
			string[] array = text.Split(this.separator, this.splitOptions);
			int num2 = Math.Max(0, x);
			if (num2 == 0)
			{
				num2 = array.Length;
			}
			List<string> list = new List<string>();
			for (int i = 0; i < num2; i++)
			{
				if (i < array.Length)
				{
					list.Add(array[i]);
				}
				else
				{
					list.Add(string.Empty);
				}
			}
			if (flag)
			{
				if (num == -1)
				{
					num = num2;
				}
				else if (num != num2)
				{
					flag = false;
				}
			}
			this.list.Add(list);
			if (y > 0 && this.list.Count >= y)
			{
				break;
			}
		}
		this.Y_Num = this.list.Count;
		if (flag)
		{
			this.X_Num = num;
		}
		reader.Close();
		return true;
	}

	// Token: 0x06001914 RID: 6420 RVA: 0x000A253C File Offset: 0x000A073C
	public bool Save_Text(string fullPath, int x = -1, int y = -1)
	{
		FileStream fileStream = new FileStream(fullPath, FileMode.Create, FileAccess.Write);
		if (fileStream == null)
		{
			MonoBehaviour.print("读取失败: " + fullPath);
			return false;
		}
		StreamWriter streamWriter = new StreamWriter(fileStream);
		bool result = this.Save_Text(streamWriter, x, y);
		streamWriter.Close();
		fileStream.Close();
		return result;
	}

	// Token: 0x06001915 RID: 6421 RVA: 0x000A2588 File Offset: 0x000A0788
	private bool Save_Text(TextWriter writer, int x = -1, int y = -1)
	{
		this.X_Num = x;
		this.Y_Num = y;
		if (this.Y_Num == -1)
		{
			this.Y_Num = this.list.Count;
		}
		for (int i = 0; i < this.Y_Num; i++)
		{
			int num = (this.X_Num != -1) ? this.X_Num : this.list[i].Count;
			for (int j = 0; j < num; j++)
			{
				writer.Write(this.list[i][j]);
				if (j != num - 1)
				{
					writer.Write(this.separator[0]);
				}
			}
			if (i != this.Y_Num - 1)
			{
				writer.Write("\n");
			}
		}
		writer.Close();
		return true;
	}

	// Token: 0x06001916 RID: 6422 RVA: 0x000A2664 File Offset: 0x000A0864
	public string Get(int x, int y)
	{
		if (y < this.list.Count && x < this.list[y].Count)
		{
			return this.list[y][x];
		}
		return string.Empty;
	}

	// Token: 0x06001917 RID: 6423 RVA: 0x000A26B4 File Offset: 0x000A08B4
	public int GetInt(int x, int y)
	{
		return int.Parse(this.Get(x, y));
	}

	// Token: 0x06001918 RID: 6424 RVA: 0x000A26C4 File Offset: 0x000A08C4
	public float GetFloat(int x, int y)
	{
		return float.Parse(this.Get(x, y));
	}

	// Token: 0x06001919 RID: 6425 RVA: 0x000A26D4 File Offset: 0x000A08D4
	public bool GetBool(int x, int y)
	{
		string text = this.Get(x, y);
		return !(text.ToLower() == "false") && !(text == "0");
	}

	// Token: 0x04001C50 RID: 7248
	private char[] separator = new char[]
	{
		'\t'
	};

	// Token: 0x04001C51 RID: 7249
	private StringSplitOptions splitOptions = StringSplitOptions.RemoveEmptyEntries;

	// Token: 0x04001C52 RID: 7250
	private List<List<string>> list = new List<List<string>>();
}
